package com.mofeng.myshop.domain.vo;

import com.mofeng.myshop.domain.po.Setting;
import com.mofeng.myshop.domain.vo.base.BaseVo;
import com.mofeng.myshop.until.Constants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 网站基础设置
 * </p>
 *
 * @author MoFeng
 * @since 2024-04-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@Schema(name = "Setting对象", description = "网站基础设置")
public class SettingVo extends BaseVo {
    @Schema(description = "键")
    private String key;

    @Schema(description = "值")
    private String value;

    @Schema(description = "text 文本类型    numText 数字文本  image 图片  select 选择框   option 单选框")
    private String type;

    public SettingVo(Setting setting) {
        super(setting);
        this.key = setting.getKey();
        this.value = setting.getValue();
        this.name = setting.getName();
        this.type = setting.getType();
    }

    public static List<SettingVo> change(Collection<Setting> settings) {
        if (settings == null) {
            return null;
        }
        return settings.stream().map(SettingVo::new).toList();
    }

    private String getKeyZh(String key){
        if (key == null){
            return null;
        }
        return switch (key) {
            case Constants.Settings.WEB_TITLE -> "网站名称";
            case Constants.Settings.WEB_KEYWORDS -> "网站关键字";
            case Constants.Settings.WEB_DESCRIPTION -> "网站介绍";
            default -> key;
        };
    }
}
